package enviornment;

import java.util.LinkedList;

import main.BuildModel;

import org.apache.commons.math3.ml.distance.EuclideanDistance;
import org.jscience.geography.coordinates.Coordinates;
import org.jscience.geography.coordinates.crs.CoordinateReferenceSystem;


/**
 * Represents location.
 * @author ggjp22
 *
 */
public class Location{
	private int locationX;
	private int locationY;
	
	/**
	 * The constructor.
	 * @param x the x coordinate of the location
	 * @param y the y coordinate of the location
	 */
	public Location(int x, int y){
		locationX =x;
		locationY =y;
	}
	public int getLocationX(){
		return this.locationX;
	}
	
	public int getLocationY(){
		return this.locationY;
	}
	
	public void setLocationX(int x){
		
		locationX =x;
	}
	public void setLocationY(int y){
		
		locationY = y;
	}
	
	/**
	 * Calculates distance between two locations.
	 * @param loc1
	 * @param loc2
	 * @return the distance
	 */
	public double distanceOf(Location loc1, Location loc2){
		double distance;
		EuclideanDistance d = new EuclideanDistance();
		double [] a = {loc1.getLocationX(), loc1.getLocationY()};
		double [] b = {loc2.getLocationX(), loc2.getLocationY() };
		distance = d.compute(a, b);
		return distance;
	}
	
	/**
	 * Multiple flood agents might be generated at the same location 
	 * because very often a few SMEs share the same location coordinates in the data file.
	 * @return a list of flood agents
	 */
	public LinkedList<Flood> getFlood(){
		LinkedList<Flood> findFlood = new LinkedList<Flood>();
		for (Flood flood: BuildModel.floodContext){
	//		System.out.println("In location class:" +flood.toString() +" this location"+ this.toString());
			if(flood.getLocation().equals(this)){
				findFlood.add(flood);
			}
		}
		return findFlood;
		
	}
	
	public String toString(){
		return "X = "+locationX+"; Y = "+locationY;
	}
	
}